package com.webchat.chat.model;

import com.webchat.chat.core.dto.evenMessage.MsgInfo;
import com.webchat.chat.core.enums.FileType;
import com.webchat.chat.core.enums.MsgType;
import com.webchat.chat.core.tools.BaseModel;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;

@Table(name = "chat_record")
@Document(collection = "chatRecord")
public class ChatRecord extends BaseModel implements Serializable {

    /**
     * 房间ID
     */
    @Column(name = "ROOM_ID")
    private String roomId;

    /**
     * 租户代号
     */
    @Column(name = "TENANT_CODE")
    private String tenantCode;

    /**
     * 发送者clientId
     */
    @Column(name = "SOURCE_CLIENT_ID")
    private String sourceClientId;

    /**
     * 接受者clientId
     */
    @Column(name = "TARGET_CLIENT_ID")
    private String targetClientId;

    /**
     * 发送者用户名
     */
    @Column(name = "SOURCE_USER_NAME")
    private String sourceUserName;

    /**
     * 接受者用户名
     */
    @Column(name = "TARGET_USER_NAME")
    private String targetUserName;

    /**
     * 时间
     */
    @Column(name = "TIME")
    private Date time;

    /**
     * 类型
     */
    @Column(name = "TYPE")
    private MsgType type;

    /**
     * 文本内容
     */
    @Column(name = "CONTENT")
    private String content;

    /**
     * 是否文件
     */
    @Column(name = "IS_FILE")
    private Boolean isFile;

    /**
     * 文件类型
     */
    @Column(name = "FILE_TYPE")
    private FileType fileType;

    /**
     * 文件路径
     */
    @Column(name = "PATH")
    private String path;

    /**
     *  消息是否需要审核
     */
    @Column(name = "AUDIT_STATUS")
    private Boolean auditStatus;

    public Boolean getAuditStatus() {
        return auditStatus;
    }

    public void setAuditStatus(Boolean auditStatus) {
        this.auditStatus = auditStatus;
    }

    @Transient
    private  MsgInfo msg;

    public MsgInfo getMsg() {
        msg= new MsgInfo();
        msg.setSourceClientId(this.sourceClientId);
        msg.setTargetClientId(this.targetClientId);
        msg.setSourceUserName(this.sourceUserName);
        msg.setTargetUserName(this.targetUserName);
        msg.setMsgType(this.type);
        msg.setContent(this.content);
        msg.setFile(this.isFile);
        msg.setFileType(this.fileType);
        msg.setPath(this.path);
        return msg;
    }



    public void setMsg(MsgInfo msg) {
        this.sourceClientId =  msg.getSourceClientId();
        this.targetClientId = msg.getTargetClientId();
        this.sourceUserName = msg.getSourceUserName();
        this.targetUserName = msg.getTargetUserName();
        this.type = msg.getMsgType();
        this.content = msg.getContent();
        this.isFile = msg.getFile();
        this.fileType = msg.getFileType();
        this.path = msg.getPath();
        this.auditStatus =msg.getCheck();
    }

    public ChatRecord(MsgInfo msg, String roomId, String tenantCode) {
        this.setMsg(msg);
        this.roomId = roomId;
        this.tenantCode = tenantCode;
        this.time =  new Date();
    }

    public ChatRecord() {

    }

    public String getRoomId() {
        return roomId;
    }

    public void setRoomId(String roomId) {
        this.roomId = roomId;
    }

    /**
     * 获取租户代号
     *
     * @return TENANT_CODE - 租户代号
     */
    public String getTenantCode() {
        return tenantCode;
    }

    /**
     * 设置租户代号
     *
     * @param tenantCode 租户代号
     */
    public void setTenantCode(String tenantCode) {
        this.tenantCode = tenantCode;
    }

    /**
     * 获取发送者clientId
     *
     * @return SOURCE_CLIENT_ID - 发送者clientId
     */
    public String getSourceClientId() {
        return sourceClientId;
    }

    /**
     * 设置发送者clientId
     *
     * @param sourceClientId 发送者clientId
     */
    public void setSourceClientId(String sourceClientId) {
        this.sourceClientId = sourceClientId;
    }

    /**
     * 获取接受者clientId
     *
     * @return TARGET_CLIENT_ID - 接受者clientId
     */
    public String getTargetClientId() {
        return targetClientId;
    }

    /**
     * 设置接受者clientId
     *
     * @param targetClientId 接受者clientId
     */
    public void setTargetClientId(String targetClientId) {
        this.targetClientId = targetClientId;
    }

    /**
     * 获取发送者用户名
     *
     * @return SOURCE_USER_NAME - 发送者用户名
     */
    public String getSourceUserName() {
        return sourceUserName;
    }

    /**
     * 设置发送者用户名
     *
     * @param sourceUserName 发送者用户名
     */
    public void setSourceUserName(String sourceUserName) {
        this.sourceUserName = sourceUserName;
    }

    /**
     * 获取接受者用户名
     *
     * @return TARGET_USER_NAME - 接受者用户名
     */
    public String getTargetUserName() {
        return targetUserName;
    }

    /**
     * 设置接受者用户名
     *
     * @param targetUserName 接受者用户名
     */
    public void setTargetUserName(String targetUserName) {
        this.targetUserName = targetUserName;
    }

    /**
     * 获取时间
     *
     * @return TIME - 时间
     */
    public Date getTime() {
        return time;
    }

    /**
     * 设置时间
     *
     * @param time 时间
     */
    public void setTime(Date time) {
        this.time = time;
    }

    /**
     * 获取类型
     *
     * @return TYPE - 类型
     */
    public MsgType getType() {
        return type;
    }

    /**
     * 设置类型
     *
     * @param type 类型
     */
    public void setType(MsgType type) {
        this.type = type;
    }

    /**
     * 获取文本内容
     *
     * @return CONTENT - 文本内容
     */
    public String getContent() {
        return content;
    }

    /**
     * 设置文本内容
     *
     * @param content 文本内容
     */
    public void setContent(String content) {
        this.content = content;
    }

    /**
     * 获取是否文件
     *
     * @return IS_FILE - 是否文件
     */
    public Boolean getIsFile() {
        return isFile;
    }

    /**
     * 设置是否文件
     *
     * @param isFile 是否文件
     */
    public void setIsFile(Boolean isFile) {
        this.isFile = isFile;
    }

    /**
     * 获取文件路径
     *
     * @return PATH - 文件路径
     */
    public String getPath() {
        return path;
    }

    /**
     * 设置文件路径
     *
     * @param path 文件路径
     */
    public void setPath(String path) {
        this.path = path;
    }

    public FileType getFileType() {
        return fileType;
    }

    public void setFileType(FileType fileType) {
        this.fileType = fileType;
    }


    @Override
    public String toString() {
        return "ChatRecord{" +
                "roomId='" + roomId + '\'' +
                ", tenantCode='" + tenantCode + '\'' +
                ", sourceClientId='" + sourceClientId + '\'' +
                ", targetClientId='" + targetClientId + '\'' +
                ", sourceUserName='" + sourceUserName + '\'' +
                ", targetUserName='" + targetUserName + '\'' +
                ", time=" + time +
                ", type=" + type +
                ", content='" + content + '\'' +
                ", isFile=" + isFile +
                ", fileType=" + fileType +
                ", path='" + path + '\'' +
                ", msg=" + msg +
                '}';
    }
}